package Dao;

import Model.StudentCourse;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;

/**
 * 查找数据库里的列名
 * Created by zhnh9 on 12/13/2016.
 * @author 张潇川
 */
public class ShowColumns extends BaseDao<String>{
    StudentCourse studentCourse = new StudentCourse();

    @Override
    public void insert(PreparedStatement preparedStatement, String Object) {

    }

    @Override
    public String setObjectByResultSet(ResultSet resultSet, int count) {
        try {
            return resultSet.getString(1);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @author 张潇川
     * @return 返回列名的动态数组
     */
    public ArrayList<String> showColumns(){
        String sql = "select COLUMN_NAME from information_schema.columns where table_name='student_course'";
        ArrayList<String> columnName = select(sql,"");
        columnName.remove(0);
        columnName.remove(0);
        //删除id，和student列
        Collections.reverse(columnName);
        //将数组倒序存储

        return columnName;
    }
}
